package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SmIdentity;
import com.ruoyi.project.system.service.ISmIdentityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 队长起止时间Controller
 */
@RestController
@RequestMapping("/system/identity")
public class SmIdentityController extends BaseController {

    @Autowired
    private ISmIdentityService smIdentityService;

    /**
     * 查询队长起止时间列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmIdentity smIdentity) {
        startPage();
        List<SmIdentity> list = smIdentityService.selectSmIdentityList(smIdentity);
        return getDataTable(list);
    }

    /**
     * 导出队长起止时间列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:export')")
    @Log(title = "队长起止时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmIdentity smIdentity) {
        List<SmIdentity> list = smIdentityService.selectSmIdentityList(smIdentity);
        ExcelUtil<SmIdentity> util = new ExcelUtil<SmIdentity>(SmIdentity.class);
        util.exportExcel(response, list, "队长起止时间数据");
    }

    /**
     * 获取队长起止时间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(smIdentityService.selectSmIdentityById(id));
    }

    /**
     * 新增队长起止时间
     */
    @PreAuthorize("@ss.hasPermi('system:time:add')")
    @Log(title = "队长起止时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmIdentity smIdentity) {
        return toAjax(smIdentityService.insertSmIdentity(smIdentity));
    }

    /**
     * 修改队长起止时间
     */
    @PreAuthorize("@ss.hasPermi('system:time:edit')")
    @Log(title = "队长起止时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmIdentity smIdentity) {
        return toAjax(smIdentityService.updateSmIdentity(smIdentity));
    }

}
